#ifndef FACE_H
#define FACE_H

#include "vertex3D.h"
#include "wsymath/matrix3d.h"
#include "geometry/math3d.h"

#include <QMap>
#include <QObject>
#include <QString>
#include "QtGui/QOpenGLFunctions"

/** 王诗阳几何面对象 */
class Face: public QObject {
    Q_OBJECT
public:
    Face(Vertex3D *fa, Vertex3D *fb, Vertex3D *fc) {
        this->setValues(fa, fb, fc);
    }
    void setValues(Vertex3D *fa, Vertex3D *fb, Vertex3D *fc) {
        this->a = fa; this->b = fb; this->c = fc;
        Vector3D *dirAB = Math3D::direction(this->a, this->b);
        Vector3D *dirAC = Math3D::direction(this->a, this->c);

        Vector3D *cross = Math3D::crossVectors(dirAB, dirAC);
        Vector3D *returnCross = cross->normalize();

        this->normal = returnCross;
        delete cross; delete dirAB; delete dirAC;
    }
    virtual Vector3D *getNormal() {
        return normal;
    }
    virtual void printVerticesOfFaceWithinRange(GLfloat *m) {
        Matrix3D::convertToTheValueWithinOpenGLRange(m, a->getX(), a->getY(), a->getZ());
        Matrix3D::convertToTheValueWithinOpenGLRange(m, b->getX(), b->getY(), b->getZ());
        Matrix3D::convertToTheValueWithinOpenGLRange(m, c->getX(), c->getY(), c->getZ());
    }
    virtual QMap<QString, Vertex3D*> *getValues() {
        QMap<QString, Vertex3D*> *singleFace = new QMap<QString, Vertex3D*>();
        singleFace->insert("a", this->a);
        singleFace->insert("b", this->b);
        singleFace->insert("c", this->c);
        return singleFace;
    }
private:
    Vertex3D *a, *b, *c; //一个三角面的三个节点
    Vector3D *normal; //一个三角面的法向量
};



#endif // GEOMETRY_FACE_H
